package reflect01;

import org.junit.Test;

/**
 * 反射(解剖类)的第一步获取要反射的类(要解剖的类)的字节码对象,才能进一步获取类中的信息
 * 三种方式:
 *   1.类名.class => 代表该类对应的字节码对象
 *   2.通过Class类中的方法获取字节码对象
 *      public static Class<?> forName(String className)
 *   3.通过Object类中的getClass方法获取字节码对象
 *     public final native Class<?> getClass()
 */
public class ReflectDemo01 {
    @Test
    public void TestMethod01(){
        System.out.println(Person.class);
        System.out.println(Person.class.toString());
    }

    @Test
    public void TestMethod02() throws ClassNotFoundException {
           /*Class<?> p = Class.forName("Person");
        System.out.println(p);//java.lang.ClassNotFoundException: Person*/
        Class<?> p = Class.forName("reflect01.Person");
        System.out.println(p);
        System.out.println(p== Person.class);
    }

    @Test
    public void TestMethod03(){
        Person person = new Person();
        System.out.println(person.getClass());
    }
    
    @Test
    public void TestMethod04()throws ClassNotFoundException{
        Class<Person> p1 = Person.class;
        Class<?> p2 = Class.forName("reflect01.Person");
        Class<? extends Person> p3 = new Person().getClass();

        System.out.println(p1 == p2);
        System.out.println(p1 == p3);
        System.out.println(p2 == p3);

    }
}
